package com.bilibili.bilibili.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bilibili.bilibili.R;
import com.bilibili.bilibili.bean.BangumiqlBean;
import com.bilibili.bilibili.customview.CircleImageView;
import com.bilibili.bilibili.utils.Time;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * 作者： 张贤伟
 * 时间： 2017/3/16 23:24
 * 类描述：番剧详情评论
 */
public class BangumiPLadapter extends RecyclerView.Adapter<BangumiPLadapter.ViewHolder> {
    private Context context;

    public BangumiPLadapter(Context context) {
        this.context = context;
    }

    private List<BangumiqlBean.DataEntity.RepliesEntity> list;

    public void getData(List<BangumiqlBean.DataEntity.RepliesEntity> list) {
        this.list = list;
        this.notifyDataSetChanged();

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_video_comment, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.name.setText(list.get(position).getMember().getUname());
        String time = Time.longToString(list.get(position).getCtime(), Time.FORMAT_DATE_TIME);
        holder.time.setText(time);


        holder.floor.setText("#"+list.get(position).getFloor());
        Glide.with(context).load(list.get(position).getMember().getAvatar()).into(holder.imageView);

        holder.context.setText(list.get(position).getContent().getMessage());
        holder.spolt.setText(list.get(position).getLike()+"");

        switch (list.get(position).getMember().getSex()) {
            case "女":
                holder.sex.setImageResource(R.drawable.ic_user_female);
                break;
            case "男":
                holder.sex.setImageResource(R.drawable.ic_user_male);
                break;
            default:
                holder.sex.setImageResource(R.drawable.ic_user_gay_border);
                break;
        }


    }





    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView name, floor, time,context,spolt;
        ImageView sex;
        CircleImageView imageView;

        public ViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.item_user_name);
            context = (TextView) itemView.findViewById(R.id.item_comment_content);
            spolt = (TextView) itemView.findViewById(R.id.item_comment_spot);

            floor = (TextView) itemView.findViewById(R.id.item_comment_floor);
            time = (TextView) itemView.findViewById(R.id.item_comment_time);
            imageView = (CircleImageView) itemView.findViewById(R.id.item_user_avatar);
            sex = (ImageView) itemView.findViewById(R.id.item_user_sex);

        }
    }
}
